package com.shawbs.vueblog.util;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;

public class Common {

    // 将实体类中的属性过滤掉
    public static HashMap filterObjectKey(Object data, ArrayList<String> keys) throws IllegalAccessException {
        HashMap<String,Object> hashMap = new HashMap<>();
        Field[] fields = data.getClass().getDeclaredFields();
        for(int i=0; i<fields.length; i++){
            Field f = fields[i];
            f.setAccessible(true);
//            System.out.println("属性名:" + f.getName() + " 属性值:" + f.get(data));

            keys.add("serialVersionUID");

            if(!keys.contains(f.getName())){
                hashMap.put(f.getName(), f.get(data));
            }

        }
        return hashMap;
    }
}
